package net.mcreator.compresstools.procedures;

import net.minecraft.world.World;
import net.minecraft.world.IWorld;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.ResourceLocation;
import net.minecraft.tags.BlockTags;
import net.minecraft.entity.Entity;
import net.minecraft.block.Block;

import net.mcreator.compresstools.item.CompressStonePickaxeItem;
import net.mcreator.compresstools.CompressToolsMod;

import java.util.Map;

public class CompressStonePickaxeBrokedProcedure {

	public static void executeProcedure(Map<String, Object> dependencies) {
		if (dependencies.get("world") == null) {
			if (!dependencies.containsKey("world"))
				CompressToolsMod.LOGGER.warn("Failed to load dependency world for procedure CompressStonePickaxeBroked!");
			return;
		}
		if (dependencies.get("x") == null) {
			if (!dependencies.containsKey("x"))
				CompressToolsMod.LOGGER.warn("Failed to load dependency x for procedure CompressStonePickaxeBroked!");
			return;
		}
		if (dependencies.get("y") == null) {
			if (!dependencies.containsKey("y"))
				CompressToolsMod.LOGGER.warn("Failed to load dependency y for procedure CompressStonePickaxeBroked!");
			return;
		}
		if (dependencies.get("z") == null) {
			if (!dependencies.containsKey("z"))
				CompressToolsMod.LOGGER.warn("Failed to load dependency z for procedure CompressStonePickaxeBroked!");
			return;
		}
		if (dependencies.get("entity") == null) {
			if (!dependencies.containsKey("entity"))
				CompressToolsMod.LOGGER.warn("Failed to load dependency entity for procedure CompressStonePickaxeBroked!");
			return;
		}
		IWorld world = (IWorld) dependencies.get("world");
		double x = dependencies.get("x") instanceof Integer ? (int) dependencies.get("x") : (double) dependencies.get("x");
		double y = dependencies.get("y") instanceof Integer ? (int) dependencies.get("y") : (double) dependencies.get("y");
		double z = dependencies.get("z") instanceof Integer ? (int) dependencies.get("z") : (double) dependencies.get("z");
		Entity entity = (Entity) dependencies.get("entity");
		double fx = 0;
		double fy = 0;
		double fz = 0;
		double nx = 0;
		double ny = 0;
		fx = ((x - entity.getPersistentData().getDouble("fx")) - 1);
		fy = ((y - entity.getPersistentData().getDouble("fy")) - 1);
		fz = ((z - entity.getPersistentData().getDouble("fz")) - 1);
		nx = fx;
		ny = fy;
		if (CompressStonePickaxeItem.block.canHarvestBlock((world.getBlockState(new BlockPos((int) x, (int) y, (int) z))))) {
			for (int index0 = 0; index0 < (int) (3); index0++) {
				for (int index1 = 0; index1 < (int) (3); index1++) {
					for (int index2 = 0; index2 < (int) (3); index2++) {
						if (!BlockTags.getCollection().getTagByID(new ResourceLocation("forge:unbreak"))
								.contains((world.getBlockState(new BlockPos((int) fx, (int) fy, (int) fz))).getBlock())) {
							if (world instanceof World) {
								Block.spawnDrops(world.getBlockState(new BlockPos((int) fx, (int) fy, (int) fz)), (World) world,
										new BlockPos((int) fx, (int) fy, (int) fz));
								world.destroyBlock(new BlockPos((int) fx, (int) fy, (int) fz), false);
							}
						}
						fx = (fx + 1);
					}
					fx = nx;
					fy = (fy + 1);
				}
				fy = ny;
				fz = (fz + 1);
			}
		}
		entity.getPersistentData().putBoolean("bkd", (true));
	}
}
